package com.zyg.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.zyg.pojo.Class;
import com.zyg.pojo.Grade;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClassMapper extends BaseMapper<Class> {
    @Override
    @Select("select class_id, class_name, grade_id from sys_class ${ew.customSqlSegment}")
    @Results({
            @Result(column = "class_id", property = "classId"),
            @Result(column = "class_name", property = "className"),
            @Result(column = "grade_id", property = "grade", javaType = Grade.class,
                    one = @One(select = "com.zyg.dao.GradeMapper.selectById"))
    })
    List<Class> selectList(IPage<Class> page, @Param(Constants.WRAPPER) Wrapper<Class> queryWrapper);

   // List<EchartsData> getGradeIndexData();
//    @Insert("INSERT INTO sys_class (class_name, grade_id) VALUES (#{className},#{gradeId})")
//@Select("SELECT * FROM sys_class WHERE class_id = #{classId}")
//@Results(id = "classResultMap", value = {
//        @Result(property = "classId", column = "class_id"),
//        @Result(property = "className", column = "class_name"),
//        @Result(property = "grade", column = "grade_id",
//                javaType = Grade.class,
//                one = @One(select = "getGrade"))
//})
//Class selectClassById(int classId);
//
//    @Select("SELECT * FROM sys_grade WHERE grade_id = #{gradeId}")
//    Grade getGrade(int gradeId);

//    @Select("SELECT c.class_id, c.class_name, c.grade_id, g.grade_name FROM sys_class c JOIN sys_grade g ON c.grade_id = g.grade_id WHERE 1=1")
//    @Results(id = "ClassMapper", value = {
//            @Result(property = "classId", column = "class_id"),
//            @Result(property = "className", column = "class_name"),
//            @Result(property = "grade", column = "grade_id",
//                    javaType = Grade.class,
//                    one = @One(select = "getGrade")),
//    })
//    List<Class> selectClassWithGrade();
    //selectClassWithGrade方法查询班级及其关联年级的信息列表，结果集映射包含班级基本信息、关联的Grade对象以及年级名称。

//    @Select("SELECT c.class_id, c.class_name, c.grade_id, g.grade_name FROM sys_class c JOIN sys_grade g ON c.grade_id = g.grade_id WHERE 1=1")
//    @Results(id = "ClassMapper", value = {
//            @Result(property = "classId", column = "class_id"),
//            @Result(property = "className", column = "class_name"),
//            @Result(property = "grade", column = "grade_id",
//                    javaType = Grade.class,
//                    one = @One(select = "getGrade")),
//    })
//    List<Class> list(IPage<Class> page, Wrapper<Class> queryWrapper);
//@Select("SELECT c.class_id, c.class_name, c.grade_id, g.grade_name FROM sys_class c JOIN sys_grade g ON c.grade_id = g.grade_id WHERE 1=1")
//@Results(id = "ClassMapper", value = {
//        @Result(property = "classId", column = "class_id"),
//        @Result(property = "className", column = "class_name"),
//        @Result(property = "grade", column = "grade_id",
//                javaType = Grade.class,
//                one = @One(select = "getGrade")),
//})
//    List<Class> selectClassListWithGrade(IPage<Class> page,  QueryWrapper<Class> queryWrapper);
//    @Select("SELECT * FROM sys_grade WHERE grade_id = #{gradeId}")
//    Grade getGrade(@Param("gradeId") Integer gradeId);
//    @Override
//    @Select("select class_id, class_name, grade_id from sys_class ${ew.customSqlSegment}")
//     @Results({
//        @Result(column = "class_id", property = "classId"),
//        @Result(column = "class_name", property = "className"),
//        @Result(column = "grade_id", property = "grade", javaType = Grade.class,
//                one = @One(select = "com.zyg.dao.GradeMapper.getGradeById"))
//     })
//    List<Class> selectList(IPage<Class> page, @Param(Constants.WRAPPER) Wrapper<Class> queryWrapper);

}
